﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using GMME.Util;
using UnityEngine;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm.Notify
{
    [DataContract]
    internal class RtmChannelPropertiesNotifyForIos : SetPropertiesReq
    {
    }
    
    [DataContract]
    public class RtmChannelPropertiesNotify
    {
        /**
         * 开发者传入的频道Id
         */
        [DataMember(Name = "channelId")]
        [Preserve]
        public string ChannelId { get; set; }

        /**
         * 频道属性
         */
        [DataMember(Name = "channelProperties")]
        [Preserve]
        public Dictionary<string, string> ChannelProperties { get; set; }
        
                
        [DataMember(Name = "channelPropertiesInner")] 
        [Preserve]
        public List<Property> ChannelPropertiesInner { get; set; }
 

        
#if UNITY_ANDROID
        internal static RtmChannelPropertiesNotify ConvertRtmChannelPropertiesNotify(
            AndroidJavaObject javaObject)
        {
            if (javaObject != null)
            {
                RtmChannelPropertiesNotify rtmChannelPropertiesNotify = new();
                rtmChannelPropertiesNotify.ChannelId = javaObject.Call<string>("getChannelId");
                rtmChannelPropertiesNotify.ChannelProperties =
                    TransferUtil.MapToDict(javaObject.Call<AndroidJavaObject>("getChannelProperties"));
                return rtmChannelPropertiesNotify;
            }

            return null;
        }

#endif

        public void ConvertPropertiesToDict()
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            if (ChannelPropertiesInner != null)
            {
                foreach (Property property in ChannelPropertiesInner)
                {
                    dict.Add(property.Key, property.Value);
                }
            }

            ChannelProperties = dict;
        }
    }
}